package com.jeecms.wicool.manager.material.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeecms.common.hibernate3.Updater;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.material.WeixinConfigurationDao;
import com.jeecms.wicool.entity.material.WeixinMaterial;
import com.jeecms.wicool.entity.material.WeixinConfiguration;
import com.jeecms.wicool.manager.material.WeixinConfigurationMng;
import com.jeecms.wicool.manager.material.WeixinMaterialMng;

@Service
@Transactional
public class WeixinConfigurationMngImpl implements WeixinConfigurationMng {
	
	private WeixinConfigurationDao dao;
	@Autowired
	public void setDao(WeixinConfigurationDao dao) {
		this.dao = dao;
	}
	
	@Transactional(readOnly = true)
	public Pagination getPage(Integer weixinMaterialId,Short configType ,int pageNo, int pageSize) {
		Pagination page = dao.getPage(weixinMaterialId, configType, pageNo, pageSize);
		return page;
	}
	@Override
	public WeixinConfiguration findById(Integer id) {
		WeixinConfiguration entity = dao.findById(id);
		return entity;
	}
	@Override
	public WeixinConfiguration update(WeixinConfiguration bean,Integer materialId) {
		WeixinMaterial wm= materialMng.findById(materialId);
		bean.setWeixinMaterial(wm);
		Updater<WeixinConfiguration> updater = new Updater<WeixinConfiguration>(bean);
		bean = dao.updateByUpdater(updater);
		return bean;
	}
	
	@Override
	public WeixinConfiguration save(WeixinConfiguration bean,Integer materialId) {
		
		WeixinMaterial wm= materialMng.findById(materialId);
		bean.setWeixinMaterial(wm);
		dao.save(bean);
		return bean;
	}

	@Override
	public WeixinConfiguration deleteById(Integer id) {
		WeixinConfiguration bean = dao.deleteById(id);
		return bean;
	}
	@Override
	public WeixinConfiguration[] deleteByIds(Integer[] ids) {
		WeixinConfiguration[] beans = new WeixinConfiguration[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}
	@Override
	public List<WeixinConfiguration> getListWeixinConfigurationByPId(Integer pId) {
		// TODO Auto-generated method stub
		return dao.getListWeixinConfigurationByPId(pId);
	}
	@Autowired
	private WeixinMaterialMng materialMng;
	
}